package com.zhongwang.business.module.taskManage.service;

import com.zhongwang.business.module.taskManage.dao.TaskBaseInfoDao;
import com.zhongwang.business.module.taskManage.dao.UnassignedTaskDao;
import com.zhongwang.business.module.taskManage.model.TaskBaseInfoModel;
import com.zhongwang.business.module.taskManage.model.UnassignedTaskModel;
import com.zhongwang.business.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TaskBaseInfoService {
    @Autowired
    private TaskBaseInfoDao taskBaseInfoDao;
    @Autowired
    private UnassignedTaskDao unassignedTaskDao;

    /**
     * 添加信息
     * @param model
     * @return
     */
    public Integer insertTaskBaseInfo(TaskBaseInfoModel model){
        model.setAssignUser(ShiroUtils.getUser().getName());
        model.setIsDelete(0);
         taskBaseInfoDao.insertTaskBaseInfo(model);
        //执行基础信息插入成功后，需要在待下达列表中，添加一条数据
        UnassignedTaskModel unassignedTaskModel=new UnassignedTaskModel();
        unassignedTaskModel.setFkId(model.getId());
        //0看板1项目基本信息
        unassignedTaskModel.setKind(1);
        unassignedTaskModel.setIsApply(1);
        unassignedTaskModel.setIsExpedited(0);
        unassignedTaskModel.setIsDelete(0);
        unassignedTaskModel.setIsPoint(0);
        unassignedTaskModel.setIsAssigned(0);
        unassignedTaskModel.setCreateUser(ShiroUtils.getUser().getName());
        unassignedTaskModel.setRemark(model.getRemark());

        return unassignedTaskDao.addUnassignedTask(unassignedTaskModel);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    public Integer delTaskBaseInfo(Integer id,Integer fkid){
        int flg=0;
        if(unassignedTaskDao.delUnassignedTask(id)>0) {
           flg= taskBaseInfoDao.delTaskBaseInfo(fkid);
        }
        return flg;
    }
}
